package com.chaosj.skill.prometheus

import com.chaosj.skill.prometheus.configurer.MeterRegistryConfigurer
import com.chaosj.skill.prometheus.customizer.ApplicationCustomizer
import com.chaosj.skill.prometheus.customizer.MeterRegistryCustomizer
import com.chaosj.skill.prometheus.properties.PrometheusProperties
import com.chaosj.skill.prometheus.properties.PrometheusPropertiesConfigAdapter
import io.micrometer.core.instrument.Clock
import io.micrometer.core.instrument.binder.MeterBinder
import io.micrometer.core.instrument.binder.jvm.ClassLoaderMetrics
import io.micrometer.core.instrument.binder.jvm.DiskSpaceMetrics
import io.micrometer.core.instrument.binder.jvm.JvmGcMetrics
import io.micrometer.core.instrument.binder.jvm.JvmMemoryMetrics
import io.micrometer.core.instrument.binder.jvm.JvmThreadMetrics
import io.micrometer.core.instrument.binder.logging.LogbackMetrics
import io.micrometer.core.instrument.binder.system.FileDescriptorMetrics
import io.micrometer.core.instrument.binder.system.ProcessorMetrics
import io.micrometer.core.instrument.binder.system.UptimeMetrics
import io.micrometer.prometheus.PrometheusMeterRegistry
import io.prometheus.client.CollectorRegistry
import io.prometheus.client.exporter.HTTPServer

/**
 * @Description:
 * @author caoyangjie
 * @date 2020年01月2020/1/23日 12:13
 * @Copyright: © 赢时胜
 */
class BootApplication {
    static void main(args){
        try {
            HTTPServer server = new HTTPServer(new InetSocketAddress(8888), CollectorRegistry.defaultRegistry,true)
            List<MeterBinder> binders = Arrays.asList(
                    new JvmGcMetrics(),new JvmMemoryMetrics(), new JvmThreadMetrics(), new ClassLoaderMetrics(),
                    new DiskSpaceMetrics(new File("E:\\")),
                    new LogbackMetrics(),new UptimeMetrics(),new ProcessorMetrics(), new FileDescriptorMetrics()
            )
            List<MeterRegistryCustomizer> registryCustomizers = Arrays.asList(new ApplicationCustomizer("Fast改造"))
            PrometheusMeterRegistry registry = new PrometheusMeterRegistry(
                    new PrometheusPropertiesConfigAdapter(new PrometheusProperties()),
                    CollectorRegistry.defaultRegistry,
                    Clock.SYSTEM
            )
            new MeterRegistryConfigurer(binders,null,registryCustomizers).configure(registry)
            while (true){
                Thread.sleep(1000L)
            }
        } catch (Exception e) {
            e.printStackTrace()
        }
    }
}
